﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PI_CS_Library.PicsNetwork_Information_Model;
using TransportLayer.Manager;
using PI_CS_Library;

namespace PI_CS_GUI
{
    public partial class MatrixPanelGUI : Form
    {
        PicsNetwork _network;
        Engine _managerEngine;
        int _id;
        bool _virtual;
        GUIDelegate _gui;
        Dictionary<int, VirtualNetworkOperatorInfo> VNOperators;

        public MatrixPanelGUI(PicsNetwork _network, Engine _managerEngine, GUIDelegate _gui, Dictionary<int, VirtualNetworkOperatorInfo> VNOperators)
        {
            InitializeComponent();

            this._gui = _gui;

            this._managerEngine = _managerEngine;
            this._network = _network;
            this.VNOperators = VNOperators;
        }

        public void GetMatrixDetails(Topology.Node _node)
        {
            label2.Text = Convert.ToString(_node.Name);
            label3.Text = Convert.ToString(_node.Id);
            _id = _node.Id;
            //int ss= _network.GetHostedMatrixId(_id,_network.g
            if (!_node.Virtual)
            {
                panel1.Visible = true;
                _virtual = false;

                PicsMatrix _vMatrix = _network.GetMatrix(_id);
                textBox1.Text = Convert.ToString(_vMatrix.PositionX);
                textBox2.Text = Convert.ToString(_vMatrix.PositionY);

                checkBox1.Checked = _vMatrix.Parameters.Accessible;

                comboBox1.Text = _vMatrix.Type;

                textBox3.Text = Convert.ToString(_vMatrix.Parameters.Delay);

                foreach (PicsLink l in _vMatrix.IncomingLinkList.Values)
                {
                    listBox1.Items.Add("From: " + l.SrcMatrix.Name + " - " + l.Id.Number);
                }
                foreach (PicsLink l in _vMatrix.OutgoingLinkList.Values)
                {
                    listBox2.Items.Add("To: " + l.SinkMatrix.Name + " - " + l.Id.Number);
                }

            }
            else
            {
                _virtual = true;
            }
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            _managerEngine.ShowNode(_id);
        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string input = (string)(listBox1.SelectedItem);
            string _linkId = input.Split(' ')[3];

            PhysicalLinkGUI _panel = new PhysicalLinkGUI(Int32.Parse(_linkId), _network, _gui, VNOperators);
            _panel.ShowDialog();
        }

        private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            string input = (string)(listBox1.SelectedItem);
            string _linkId = input.Split(' ')[3];

            PhysicalLinkGUI _panel = new PhysicalLinkGUI(Int32.Parse(_linkId), _network, _gui, VNOperators);
            _panel.ShowDialog();
        }
    }
}
